package com.eastfair.config.controller.entitycontroller;

import com.eastfair.config.entity.FriendLink;
import com.eastfair.config.service.entityservice.FriendLinkService;
import com.eastfair.core.base.R;
import com.eastfair.projectcore.vo.ConfigAttributeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 友情链接控制类
 * <p>
 * Date:2021/8/7
 * Time:15:37
 *
 * @author zjn
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/friendLink")
@Api(value = "友情链接控制类", tags = "友情链接控制类")
public class FriendLinkController {

    @Autowired
    private FriendLinkService friendLinkService;

    /**
     * 获取友情链接属性信息
     *
     * @return
     */
    @GetMapping("/getAttributes")
    @ApiOperation(value = "获取友情链接属性信息", notes = "获取友情链接属性信息")
    public R<List<ConfigAttributeVO>> getFriendLinkAttributes() {
        return R.success(friendLinkService.getAttributes());
    }

    /**
     * 获取友情链接列表
     *
     * @param friendLink 友情链接列表过滤条件
     * @return
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取友情链接列表", notes = "获取友情链接列表")
    public R<List<FriendLink>> getList(@RequestBody(required = false) FriendLink friendLink) {
        return R.success(friendLinkService.getList(friendLink));
    }

    /**
     * 获取友情链接
     *
     * @param flagId 标识id
     * @return
     */
    @GetMapping("/get/{flagId}")
    @ApiOperation(value = "获取友情链接", notes = "获取友情链接")
    public R<FriendLink> getFriendLink(@PathVariable("flagId") Long flagId) {
        return friendLinkService.get(flagId);
    }

    /**
     * 新增友情链接
     *
     * @param friendLink 友情链接实体
     * @return 是否成功
     */
    @PostMapping("/saveEntity")
    @ApiOperation(value = "新增友情链接", notes = "新增友情链接")
    public R<Boolean> saveEntity(@RequestBody FriendLink friendLink) {
        return friendLinkService.saveEntity(friendLink);
    }

    /**
     * 删除友情链接
     *
     * @param flagId 友情链接标识id
     * @return 是否成功
     */
    @DeleteMapping("/{flagId}")
    @ApiOperation(value = "删除友情链接", notes = "删除友情链接")
    public R<Boolean> deleteEntity(@PathVariable("flagId") Long flagId) {
        return friendLinkService.deleteEntity(flagId);
    }

    /**
     * 修改友情链接信息
     *
     * @param friendLink 友情链接信息
     * @return 是否成功
     */
    @PutMapping("/updateEntity")
    @ApiOperation(value = "修改友情链接信息", notes = "修改友情链接信息")
    public R<Boolean> updateEntity(@RequestBody FriendLink friendLink) {
        return friendLinkService.updateEntity(friendLink);
    }

}
